//
//  ConsultTwoViewController.m
//  110
//
//  Created by lanou on 16/4/11.
//  Copyright © 2016年 乔砥. All rights reserved.
//

#import "ConsultDetailTwoViewController.h"
#import "ConsultTwoDetailTableViewCell.h"
#import "ConsultTwoDetailViewControllerModel.h"
#import "RequestManager.h"
@interface ConsultDetailTwoViewController () <UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *array;


@property(nonatomic,strong)UIImageView *imageView;



@property(nonatomic,strong)ConsultTwoDetailTableViewCell * twocell;

@end

@implementation ConsultDetailTwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //  self.tabBarController.tabBar.hidden = YES;
    
    self.navigationItem.title = @"保健养生";
    
    self.view.backgroundColor = [UIColor blackColor];
    
    
    UIBarButtonItem *leftBarButton  = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonAction:)];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView .dataSource = self;
    
    
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    
    
    // 注册cell
    [self.tableView registerClass:[ConsultTwoDetailTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    [self.view addSubview:_tableView];
    
    
    [self request];
    
}


-(void)request
{
    NSString  *str = [NSString stringWithFormat:@"http://apphy02.caeac.com.cn/500e32BD52027E652AA00003/androidapi/indexarticlec.php?w=1284&d=%@",_myId];
    [RequestManager requestWithUrl:str requestType:RequestTypeGET parDic:nil finish:^(NSData *data) {
        
        NSDictionary *dic=  [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        
        _array = [ConsultTwoDetailViewControllerModel getData:dic];
        
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [self.tableView reloadData];
        });
        
    } error:^(NSError *error) {
        
        
        NSLog(@"网络错误");
        
    }];
    
    
    
    
    
    
    
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _array.count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ConsultTwoDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    ConsultTwoDetailViewControllerModel *model = _array[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    [cell getData:model];
    return cell;
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ConsultTwoDetailViewControllerModel *model = _array[indexPath.row];
    return [ConsultTwoDetailTableViewCell cellHeghtForRow:model];
    
}


/*
 //缩小的圈圈*/
-(void)scalaCoop
{
    CGRect rect = CGRectInset(_imageView.frame, -600, -600);
    
    CGPathRef startPath = CGPathCreateWithEllipseInRect(rect, NULL);
    CGPathRef endPath   = CGPathCreateWithEllipseInRect(_imageView.frame, NULL);
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.path = endPath;
    
    self.view.layer.mask = maskLayer;
    
    CABasicAnimation *pingAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
    pingAnimation.delegate = self;
    [pingAnimation setValue:@"animate2" forKey:@"animate2"];
    
    pingAnimation.fromValue = (__bridge id)(startPath);
    pingAnimation.toValue   = (__bridge id)(endPath);
    pingAnimation.duration  = 1;
    
    pingAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
    [maskLayer addAnimation:pingAnimation forKey:@"pingInvert2"];
    
    CGPathRelease(startPath);
    CGPathRelease(endPath);
    
    
    
    
    // 定时器.先执行跳转动画  再进行跳转
    NSTimer * time = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(aaaaa:) userInfo:nil repeats:NO];
    
}

- (void)aaaaa: (NSTimer *)aa
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}


// 左上角返回按钮触发的方法
-(void)leftBarButtonAction:(UIBarButtonItem *)left
{
    
    [self scalaCoop];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
